import axios from 'axios'
//initState
const initState = {
    msg:'hello',
    list:[]
}

//action
export const changeMsg =(msg)=>{
    return {
        type:'CHANGE_MSG',
        msg
    }
}

export const fetchData = ()=>{
    return async dispatch =>{
        axios.get('http://api.pingcc.cn?mhname=海贼王').then(res=>{
            dispatch({
                type:'CHANGE_LIST',
                list:res.data.list
            })
        })
    }
}

//reducer
export default ((state=initState,action)=>{
    switch (action.type) {
        case 'CHANGE_MSG':
            return {...state,msg:action.msg}
        case 'CHANGE_LIST':
            return {...state,list:action.list}
        default:
            return state
    }
})